package com.ternnetwork.commons.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;


public class ExtendedFileUtils extends FileUtils{
	
	
	public static void main(String[] args){
		
		compareFiles("/Users/xuwenfeng/Documents/ws/avocado-batch-webapp/target/avocado-batch-webapp-0.0.1/WEB-INF/lib", "/Users/xuwenfeng/Documents/ws/ocms-batch/target/ocms-batch-0.0.1-SNAPSHOT/WEB-INF/lib");
	}
	
	
	public  static void makeDirs(String dirs){
		File saveDirFile = new File(dirs);
		if (!saveDirFile.exists()) {
			saveDirFile.mkdirs();
		}
	}
	
	
    public static void compareFiles(String fileFrom ,String fileTo){
		
		
		File fileF=new File(fileFrom);
		File fileT=new File(fileTo);
		List<String> fileNameListFrom=getFileNameList(fileF);
		List<String> fileNameListTo=getFileNameList(fileT);
		
		System.out.println(fileFrom+"比"+fileTo+"多的文件有");
		for(String fileNameFrom:fileNameListFrom){
			if(!fileNameListTo.contains(fileNameFrom)){
				System.out.println(fileNameFrom);
			}
		}
		System.out.println(fileTo+"比"+fileFrom+"多的文件有");
		for(String fileNameTo:fileNameListTo){
			if(!fileNameListFrom.contains(fileNameTo)){
				System.out.println(fileNameTo);
			}
		}
	}

	private static List<String> getFileNameList(File fileF) {
		List<String> fileNameList=new ArrayList<String>();
		if(fileF.isDirectory()){
			
			File[] fileList=fileF.listFiles();
			
			for(File file:fileList){
				fileNameList.add(file.getName());
			}
		}
		return fileNameList;
	}
}
